import { Body, Controller, Get, Inject, Param, ParseIntPipe, ParseUUIDPipe, Post, Query, Req, UseGuards } from '@nestjs/common';
import { ArticleCommentService } from './article-comment.service'
import { CreateArticleCommentDto } from './dtos/create-article-comment.dto'
import { AuthGuard } from '../../guard/auth.guard'
import { ValidationPipe } from '../../pipes/validate.pipe'
import { SearchDto } from '../../dtos/search.dto'


@Controller('article/comment')
export class ArticleCommentController {
    constructor(
        private readonly articleCommentService: ArticleCommentService
    ) { }

    @Get(':article_id')
    @UseGuards(AuthGuard)
    getArticleComment(@Param('article_id', ParseUUIDPipe) article_id, @Query(new ValidationPipe()) searchDto: SearchDto) {
        return this.articleCommentService.findAll(article_id, searchDto)
    }

    @Get('/replay/:parent_id')
    @UseGuards(AuthGuard)
    getArticleCommentReplay(@Param('parent_id', ParseUUIDPipe) parent_id, @Query(new ValidationPipe()) searchDto: SearchDto) {
        return this.articleCommentService.findAllReplay(parent_id, searchDto)
    }


    @Post()
    @UseGuards(AuthGuard)
    postArticleComment(
        @Req() req,
        @Body(ValidationPipe) createArticleCommentDto: CreateArticleCommentDto
    ) {
        return this.articleCommentService.create(req.userId, createArticleCommentDto)
    }
}
